package com.ibiaoke.order.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.order.entity.XcxAddress;
import com.ibiaoke.order.entity.XcxAddressExample;
import com.ibiaoke.order.mapper.XcxAddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;

@Repository
public class XcxAddressDao extends BaseDao<XcxAddress, XcxAddressExample, Integer, XcxAddressMapper> {

    @Autowired
    private XcxAddressMapper xcxAddressMapper;

    @Override
    public XcxAddressMapper getMapper() {
        return xcxAddressMapper;
    }

    public List<XcxAddress> listXcxAddress(Integer customerId) {
        XcxAddressExample example = new XcxAddressExample();
        example.createCriteria().andDelStatusEqualTo((byte) CommonConsts.NO)
                .andUserIdEqualTo(customerId);
        return xcxAddressMapper.selectByExample(example);
    }

    public int delete(Integer addressId) {
        XcxAddress xcxAddress = new XcxAddress();
        xcxAddress.setAddressId(addressId);
        xcxAddress.setDelStatus((byte) CommonConsts.YES);
        xcxAddress.setUpdateTime(new Date());
        return updateByPrimaryKeySelective(xcxAddress);
    }
}
